package cn.jark.example.web.controller;

import cn.jark.example.web.entity.User;
import cn.jark.example.web.service.TestService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.document.Document;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
 * @author 雨一直夏灬(须知少年凌云志, 曾许人间第一流)
 * @since 2020-10-30
 */
@RestController
public class Demo2Controller {

    @Autowired
    TestService testService;


    @Autowired
    ElasticsearchRestTemplate restTemplate;

    @GetMapping("hi")
    public String demo() {
        return testService.sayHello();
    }


    @GetMapping("/es")
    public void es() {
        final boolean demo = restTemplate.indexOps(IndexCoordinates.of("demo")).create();
        System.out.println(demo);
    }


    @GetMapping("/es2")
    public User es2() {
        return restTemplate.save(new User("suelee", 12));
    }

    @GetMapping("/hi2")
    @SentinelResource(value="hi2")
    public String hi(@RequestParam(value = "name",defaultValue = "forezp",required = false)String name){

        return "hi "+name;
    }

}
